﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class NhomDanhMucSanPhamDAO
    {
        public static NhomDanhMucSanPhamDTO LayNhomDanhMucSanPhamTheoID(int id)
        {
            MyDataBaseDataContext myDB = new MyDataBaseDataContext();
            NHOM_DANH_MUC_SAN_PHAM temp = myDB.NHOM_DANH_MUC_SAN_PHAMs.Single(c => c.ID == id);
            return new NhomDanhMucSanPhamDTO(temp.ID, temp.TenNhomDanhMucSanPham);
        }

        public static bool ThemNhomDanhMucSanPham(NhomDanhMucSanPhamDTO nhomdanhmucsanphamDTO)
        {
            NHOM_DANH_MUC_SAN_PHAM temp = new NHOM_DANH_MUC_SAN_PHAM();
            temp.ID = nhomdanhmucsanphamDTO.ID;
            temp.TenNhomDanhMucSanPham = nhomdanhmucsanphamDTO.TenDanhMucSanPham;

            MyDataBaseDataContext myDB = new MyDataBaseDataContext();
            try
            {
                myDB.NHOM_DANH_MUC_SAN_PHAMs.InsertOnSubmit(temp);
                myDB.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool XoaNhomDanhMucSanPhamTheoID(int id)
        {
            MyDataBaseDataContext myDB = new MyDataBaseDataContext();
            NHOM_DANH_MUC_SAN_PHAM temp = myDB.NHOM_DANH_MUC_SAN_PHAMs.Single(c => c.ID == id);
            try
            {
                myDB.NHOM_DANH_MUC_SAN_PHAMs.DeleteOnSubmit(temp);
                myDB.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
